/*
 * main.cc
 *
 *  Created on: Nov 22, 2010
 *      Author: fify
 */

#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

class Interval
{
public:
	int start, end;

	int efficiency;

	/*
	 * next: The nearest next loop after a short rest
	 */
	int next;

	int total;

	Interval(){}
	Interval(int s, int e)
	{
		start = s;
		end = e;
	}

	bool operator<(const Interval &inv) const
	{
		return start < inv.start;
	}
};

Interval inv[1005];

void solve(int n, int m, int r)
{
	for(int i = 0;i<m;i++)
	{
		scanf("%d%d%d", &inv[i].start, &inv[i].end, &inv[i].efficiency);
		inv[i].end += r;
		inv[i].total = 0;
	}

	inv[m].start = n + n;
	inv[m].end = n + n + n;
	inv[m].total = 0;

	sort(inv, inv + m + 1);

	for(int i = 0;i<m;i++)
	{
		inv[i].next = lower_bound(inv, inv + m + 1, Interval(inv[i].end, inv[i].end + 1)) - inv;
	}

	for(int i = 0;i<m;i++)
	{
		inv[i + 1].total = max(inv[i].total, inv[i+1].total);
		inv[inv[i].next].total = max(inv[i].total + inv[i].efficiency, inv[inv[i].next].total);
	}

	printf("%d\n", inv[m].total);
}

int main()
{
	int n, m, r;

	scanf("%d%d%d", &n, &m, &r);
	solve(n, m, r);
}
